package com.longrise.android.byjk.plugins.aboutme.personalInfo.person_honor;

import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.common.Control;
import com.longrise.android.byjk.common.UrlConstants;
import com.longrise.android.byjk.model.UserInfor;
import com.longrise.android.loaddata.newloaddata.LoadDataManagerFather;
import com.longrise.common.datasource.remote.LoadDataManager;

/**
 * Created by Administrator on 2018/3/8.
 * 添加个人荣誉的presenter
 */

public class AddPersonHonorPresenter extends AddPersonHonorContract.Presenter {


    @Override
    protected void init() {

    }

    //新增个人荣誉
    @Override
    public void addPersonHonorData(String honordec) {
        mView.setVisible(false);
        mView.showLoadingDialog();
        Control.setPersonHonor(honordec);
        String usersfzh = UserInfor.getInstance().getUsersfzh();
        String userid = UserInfor.getInstance().getUserid();
        EntityBean bean = new EntityBean();
        bean.set("cardno", usersfzh);
        bean.set("userid ", userid);
        bean.set("personalhonordesc ", honordec);
        EntityBean bean1 = new EntityBean();
        bean1.set("bean", bean);
        LoadDataManager.getInstance().callService2(null, UrlConstants.BaseUrl, "insh_user_personalhonor", bean1, new LoadDataManager.OnRequestCallListener2() {

            @Override
            public void onSuccess(String key, String service, Object result) {
                try {
                    EntityBean bean = (EntityBean) result;
                    int resultstate = bean.getInt("resultstate");
                    if (resultstate == 1) {
                        mView.showToast("保存成功");
                        mView.refreshData(bean);
                    } else {
                        mView.showToast(bean.getString("resultdesc"));
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }


            @Override
            public void onFinished(String key, String service) {
                mView.dismissLoadingDialog();
                mView.setVisible(true);
            }

            @Override
            public void onError(String key, String service, LoadDataManagerFather.ResultType resultType) {

            }

        });
    }


    //修改个人荣誉
    @Override
    public void modifyPersonHonorData(String honordec, String honorId) {
        Control.setPersonHonor(honordec);
        String usersfzh = UserInfor.getInstance().getUsersfzh();
        String userid = UserInfor.getInstance().getUserid();
        EntityBean bean = new EntityBean();
        bean.set("id", honorId);
        bean.set("cardno", usersfzh);
        bean.set("userid ", userid);
        bean.set("personalhonordesc ", honordec);
        EntityBean bean1 = new EntityBean();
        bean1.set("bean", bean);
        mView.setVisible(false);
        mView.showLoadingDialog();
        LoadDataManager.getInstance().callService2(null, UrlConstants.BaseUrl, "insh_user_UpdatePersonalhonor", bean1, new LoadDataManager.OnRequestCallListener2() {

            @Override
            public void onSuccess(String key, String service, Object result) {
                try {
                    EntityBean bean = (EntityBean) result;
                    int resultstate = bean.getInt("resultstate");
                    if (resultstate == 1) {
                        mView.showToast("修改成功");
                        mView.refreshData(bean);
                    } else {
                        mView.showToast(bean.getString("resultdesc"));
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }


            @Override
            public void onFinished(String key, String service) {
                mView.dismissLoadingDialog();
                mView.setVisible(true);
            }

            @Override
            public void onError(String key, String service, LoadDataManagerFather.ResultType resultType) {

            }

        });
    }

}
